package com.test.sdk.core.util;

import java.util.Random;

/**
 * @author 徒有琴
 */
public class AccountUtil {
    public static boolean checkMobile(String mobile) {
        if (mobile == null || mobile.length() != 11) {
            return false;
        }
        String reg = "^1[3-8]\\d{9}$";
        return mobile.matches(reg);
    }
    public static boolean checkUsername(String name) {
        if (name == null||name.trim().length()==0) {
            return false;
        }
        String reg="^[a-zA-Z]\\w{5,31}";
        return name.matches(reg);
    }

    public static String getRandomNum(int len){
        StringBuilder builder=new StringBuilder();
        Random random=new Random();
        for (int i = 0; i < len; i++) {
            builder.append(random.nextInt(10));
        }
        return builder.toString();
    }

    public static int getUserType(String account){
        if(checkMobile(account)){
            return SdkConstants.ACCOUNT_TYPE_MOBILE;
        }
        if(checkUsername(account)){
            return SdkConstants.ACCOUNT_TYPE_USERNAME;
        }
        return SdkConstants.ACCOUNT_TYPE_UNKNOWN;
    }

    public static void main(String[] args) {
//        System.out.println(checkMobile("137aaaa6888"));
//        System.out.println(getRandomNum(6));
        System.out.println(checkUsername("sfca"));
        try {
            System.out.println(DES.encode("123456",Base64.encode("8cP7Vbru".getBytes())));
            System.out.println(DES.decode("4XIIh2+LzfU=",Base64.encode("4rHxmaVR".getBytes())));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
